﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Hadron
{
    class GameController
    {
        private Keys m_keyForward, m_keyBackward, m_keyRotateLeft, m_keyRotateRight,
            m_keyFire, m_keyShield, m_keyStart, m_keyBack;

        public GameController()
        {
            m_keyForward = Keys.Up;
            m_keyBackward = Keys.Down;
            m_keyRotateLeft = Keys.Left;
            m_keyRotateRight = Keys.Right;
            m_keyFire = Keys.Z;
            m_keyShield = Keys.X;
            m_keyStart = Keys.Space;
            m_keyBack = Keys.Escape;
        }

        public bool Forward
        {
            get
            {
                return Keyboard.GetState().IsKeyDown(m_keyForward)
                    || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadUp);
            }
        }

        public bool Backward
        {
            get
            {
                return Keyboard.GetState().IsKeyDown(m_keyBackward)
                    || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadDown);
            }
        }

        public bool RotateLeft
        {
            get
            {
                return Keyboard.GetState().IsKeyDown(m_keyRotateLeft)
                    || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadLeft);
            }
        }

        public bool RotateRight
        {
            get
            {
                return Keyboard.GetState().IsKeyDown(m_keyRotateRight)
                    || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadRight);
            }
        }

        public bool Fire
        {
            get
            {
                return Keyboard.GetState().IsKeyDown(m_keyFire)
                    || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.A);
            }
        }

        public bool Shield
        {
            get
            {
                return Keyboard.GetState().IsKeyDown(m_keyShield)
                    || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.B);
            }
        }

        public bool Start
        {
            get
            {
                return Keyboard.GetState().IsKeyDown(m_keyStart)
                    || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start);
            }
        }

        public bool Back
        {
            get
            {
                return Keyboard.GetState().IsKeyDown(m_keyBack)
                    || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back);
            }
        }

        public bool Neutral
        {
            get {
                return !Forward && !Backward && !RotateLeft && !RotateRight
                    && !Fire && !Shield && !Start && !Back;
            }
        }
    }
}
